<?php
namespace app\wxapp\controller;

use think\Db;


class Logout 
{   
   

    //验证授权码登陆
    public function index(){
        $Wxapp_user = db('wxapp_user');
        //获取授权码
        $auth_code  = input('auth_code');
        $session_id = input('session_id');
        $wx_user_info = $Wxapp_user->where('session_id',$session_id)->find();
        return json($wx_user_info);die;
        //验证授权码是否存在，存在返回赛事信息
        if($result = db('event')->where('auth_code',$auth_code)->find()){

            //将授权码插入wxapp的表中
            db('wxapp_user')->where('id',$wx_user_info['id'])->update(array('auth_code'=>$auth_code));
            //记录计费信息
            $consumption_info['use_time']      = time();
            $consumption_info['event_id']      = $result['id'];
            $consumption_info['event_name']    = $result['event_name'];
            $consumption_info['auth_code']     = $auth_code;
            $consumption_info['wx_nick_name']  = $wx_user_info['nickName'];
            $consumption_info['wx_avatar_url'] = $wx_user_info['avatarUrl'];
            $consumption_info['wx_openid']     = $wx_user_info['openid'];
          
            Db::name('consumption')->insert($consumption_info);
            $data['state']     = 1;
            $data['info']      = '授权码通过';
            $data['event_id']  = $result['id']; //赛事id
            $data['consumption_id'] = Db::name('consumption')->getLastInsID();

        }else{
            $data['state']     = 0;
            $data['info'] = '授权码不正确';
        }
        return json($data);
    }
}
